<template>
  <div class="cate-hot">
    <div class="title">
      热销推荐
    </div>
    <div class="goods-list">
      <el-row :gutter="20">
        <el-col
          v-for="(t, index) in recommed"
          :key="t.id"
          :span="12"
        >
          <div
            v-if="index < 2"
            class="grid-content"
          >
            <img
              :src="t.defaultAlbum"
              alt=""
            >

            <div class="goods-info">
              <div class="goods-name">
                {{ t.pName }}
              </div>
              <div
                class="goods-button"
                @click="toBuy(t)"
              >
                点击购买<img
                  src="../../assets/img/more.png"
                  alt=""
                >
              </div>
            </div>
          </div>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col
          v-for="(t, index) in recommed"
          :key="t.id"
          :span="8"
        >
          <div
            v-if="index >= 2"
            class="grid-content middle"
          >
            <img
              :src="t.defaultAlbum"
              alt=""
            >

            <div class="goods-info">
              <div class="goods-name">
                {{ t.pName }}
              </div>
              <div
                class="goods-button"
                @click="toBuy(t)"
              >
                点击购买<img
                  src="../../assets/img/more.png"
                  alt=""
                >
              </div>
            </div>
          </div>
        </el-col>
      </el-row>
    </div>
    <div class="more">
      <img
        src="../../assets/img/logo2.png"
        alt=""
        @click="toList"
      >
    </div>
  </div>
</template>

<script>
export default {
  name: "",
  components: {},
  data() {
    return {
      list: [],
      recommed: [],
    };
  },
  methods: {
    toList() {
      this.$router.push({ path: "/fruit" });
    },
    toBuy(item) {
      this.$router.push({ path: "/fruit/detail?id=" + item.pid });
    },
    getData(id) {
      this.recommed = [];
      let data = {
        queryCondition: {
          order: [
            {
              fieldname: "iOrder",
              direction: "asc",
            },
          ],
          pageindex: 1,
          pagesize: 100,
          where: [
            {
              fieldname: "categoryid",
              valuefrom: id,
            },
          ],
        },
      };
      this.$api.home.getProductList(data).then((res) => {
        if (res.code == 200) {
          this.list = res.data.data;
          let flag = 0;
          res.data.data.forEach((item) => {
            if (item.bRecommended) {
              if (flag < 5) {
                this.recommed.push(item);
                flag++;
              }
            }
          });
        }
      });
    },
  },
};
</script>

<style scoped lang="scss">
.cate-hot {
  padding: 0 16.19rem;
  margin-top: 2.19rem;
  display: flex;
  flex-direction: column;

  .title {
    width: 11.25rem;
    height: 3.44rem;
    background: rgba(0, 0, 0, 1);
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.5rem;
    font-family: Microsoft YaHei;
    font-weight: 400;
    color: rgba(234, 234, 234, 1);
  }

  .goods-list {
    margin-top: 1.88rem;
    width: 100%;

    .grid-content {
      border-radius: 4px;
      height: 22rem;
      background: #fff;
      margin-bottom: 1.31rem;
      display: flex;
      justify-content: space-around;
      align-items: center;
      img {
        width: 20rem;
        height: 20rem;
        object-fit: contain;
      }
      .goods-info {
        display: flex;
        flex-direction: column;
        .goods-name {
          font-size: 1.5rem;
          font-family: Microsoft YaHei;
          font-weight: 400;
          color: rgba(0, 0, 0, 1);
          line-height: 2.42rem;
          max-width: 13rem;
          overflow: hidden;
          text-overflow: ellipsis;
        }

        .goods-button {
          width: 7.5rem;
          height: 1.88rem;
          background: rgba(4, 0, 0, 1);
          font-size: 0.88rem;
          font-family: Microsoft YaHei;
          font-weight: 400;
          color: rgba(255, 255, 255, 1);
          display: flex;
          justify-content: center;
          align-items: center;
          margin-top: 1.69rem;
          cursor: pointer;
          img {
            margin-left: 0.5rem;
            width: 1.06rem;
            height: 1.25rem;
          }
        }
      }
      &.middle {
        height: 22rem;
        img {
          width: 11rem;
          height: 11rem;
          object-fit: contain;
        }
        .goods-info {
          display: flex;
          flex-direction: column;
          .goods-name {
            font-size: 1.5rem;
            font-family: Microsoft YaHei;
            font-weight: 400;
            color: rgba(0, 0, 0, 1);
            line-height: 2.42rem;
          }
          .goods-button {
            width: 7.5rem;
            height: 2.19rem;
            background: rgba(4, 0, 0, 1);
            font-size: 0.88rem;
            font-family: Microsoft YaHei;
            font-weight: 400;
            color: rgba(255, 255, 255, 1);
            display: flex;
            justify-content: center;
            align-items: center;
            margin-top: 1.69rem;
            cursor: pointer;
            img {
              margin-left: 0.5rem;
              width: 1.06rem;
              height: 1.25rem;
            }
          }
        }
      }
    }
  }
  .more {
    height: 2.5rem;
    background: rgba(0, 0, 0, 1);
    display: flex;
    justify-content: flex-end;
    align-items: center;
    padding: 0 1.44rem;
    img {
      width: 7.38rem;
      cursor: pointer;
    }
  }
  .adv {
    width: 100%;
    margin-top: 3.69rem;
    object-fit: contain;
  }
}
</style>
